package cn.ms.doctor.Controller;

import cn.ms.doctor.Entity.Order;
import cn.ms.doctor.Service.OrderService;
import cn.ms.doctor.Utils.DataStandardUtils;
import cn.ms.doctor.Utils.GlobalMessage;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/Order")
public class OrderController {

    @Resource
    OrderService orderService;

    @RequestMapping("/isLogin/isSystemAndDrugs/getOrders")
    public Object getOrders(@RequestBody Map<String,Object> params){
        if (DataStandardUtils.standardKeyIsEmpty(params,"pageIndex","pageSize")) {
            return new GlobalMessage(200,2,"非法请求...",null);
        }
        Map<String , Object> data=orderService.getOrders(params);
        return new GlobalMessage(200,0,null,data);
    }

    @RequestMapping("/isLogin/isSystemAndDrugs/updateState")
    public Object updateState(@RequestBody Order order){
        if (StringUtils.isEmpty(order.getOrderId())||StringUtils.isEmpty(order.getOrderState())||StringUtils.isEmpty(order.getUserId())) {
            return new GlobalMessage(200,2,"非法请求...",null);
        }
        if (order.getOrderState()<0||order.getOrderState()>2) {
            return new GlobalMessage(200,1,"请传递正确的参数内容...",null);
        }
        if (!orderService.updateStateByOrderId(order)){
            return new GlobalMessage(200,3,"出现异常,请联系管理员...",null);
        }
        return new GlobalMessage(200,0,null,"修改成功...");
    }

}
